<template>
  <div>
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-input
          v-model="dataForm.key"
          placeholder="干货id/干货名"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      style="width: 100%"
      @selection-change="selectionChangeHandle"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      ></el-table-column>
      <el-table-column fixed prop="id" label="id"> </el-table-column>
      <!-- <el-table-column prop="skuId" label="sku_id" width="120">
      </el-table-column>
      <el-table-column prop="spuId" label="spu_id" width="120">
      </el-table-column> -->
      <el-table-column prop="spuName" label="干货名字" width="120">
      </el-table-column>
      <el-table-column prop="skuPic" label="干货默认图片" width="150">
        <template slot-scope="scope">
          <!-- <el-image
              style="width: 100px; height: 80px"
              :src="scope.row.logo"
          fit="fill"></el-image>-->
          <img :src="scope.row.skuPic" style="width: 100px; height: 80px" />
        </template>
      </el-table-column>
      <el-table-column prop="username" label="用户名称" width="120">
      </el-table-column>
      <el-table-column prop="star" label="星级" width="120"> </el-table-column>
      <!-- <el-table-column prop="memberIp" label="会员ip" width="120">
      </el-table-column> -->
      <el-table-column prop="createTime" label="创建时间" width="120">
      </el-table-column>
      <el-table-column prop="showStatus" label="显示状态" width="120">
      </el-table-column>
      <el-table-column prop="spuAttributes" label="购买时属性组合" width="120">
      </el-table-column>
      <!-- <el-table-column prop="likesCount" label="点赞数" width="120">
      </el-table-column>
      <el-table-column prop="replyCount" label="回复数" width="120">
      </el-table-column> -->
      <!-- <el-table-column prop="resources" label="评论图片" width="120">
        <template slot-scope="scope">
          <img :src="scope.row.resources" style="width: 100px; height: 80px" />
        </template>
      </el-table-column> -->
      <!-- <el-table-column prop="content" label="内容" width="120">
      </el-table-column> -->
      <el-table-column prop="memberIcon" label="用户头像" width="150">
        <template slot-scope="scope">
          <img :src="scope.row.memberIcon" style="width: 100px; height: 80px" />
        </template>
      </el-table-column>
      <!-- <el-table-column prop="commentType" label="评论类型" width="120">
      </el-table-column> -->
      <el-table-column fixed="right" label="操作" width="150">
        <template slot-scope="scope">
          <el-button
            @click="searchHandle(scope.row.id)"
            type="text"
            size="small"
            >查看</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="deleteHandle(scope.row.id)"
            >删除</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="updateHandle(scope.row.id)"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- 弹窗查看 -->
    <search-comment
      v-if="searchVisible"
      ref="searchComment"
      @refreshDataList="getDataList"
    ></search-comment>
    <!-- 弹窗修改 -->
    <update-comment
      v-if="updateVisible"
      ref="updateComment"
      @refreshDataList="getDataList"
    ></update-comment>
  </div>
</template>

<script>
import SearchComment from "./comment-search";
import UpdateComment from "./comment-update";
export default {
  name: "RenrenFastVueComments",

  data() {
    return {
      dataForm: {
        key: ""
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      searchVisible: false,
      deleteVisible: false,
      //多选属性
      dataListSelections: [],
      updateVisible: false
    };
  },

  mounted() {},
  components: {
    SearchComment,
    UpdateComment
  },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/product/spucomment/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.dataForm.key
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          //设置分页数据
          this.totalPage = data.page.totalCount;

          //设置评论数据
          console.log(data.page);
          this.dataList = data.page.list;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 查看评论详细信息
    searchHandle(id) {
      this.searchVisible = true;
      this.$nextTick(() => {
        this.$refs.searchComment.init(id);
      });
    },
    // 修改
    updateHandle(id) {
      this.updateVisible = true;
      this.$nextTick(() => {
        this.$refs.updateComment.init(id);
      });
    },
    //删除评论
    deleteHandle(id) {
      var ids = id
        ? [id]
        : this.dataListSelections.map(item => {
            return item.brandId;
          });
      this.$confirm(
        `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        this.$http({
          url: this.$http.adornUrl("/product/spucomment/delete"),
          method: "post",
          data: this.$http.adornData([id], false)
        }).then(({ data }) => {
          this.getDataList();
        });
      });
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    }
  }
};
</script>

<style lang="scss" scoped></style>
